package com.csc.controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.csc.dao.BookDAO;
import com.csc.dao.DAOFactory;
import com.csc.data.BookObj;
import com.csc.data.BookObjManager;

/**
 * Servlet implementation class BookViewServlet
 */
public class BookStoreServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private DAOFactory odbcDAOFactory;
	private BookDAO bookDao;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookStoreServlet() {
    	super();
    	odbcDAOFactory = DAOFactory.getDAOFactory(DAOFactory.ODBC);
    	bookDao = odbcDAOFactory.createBookDao();
        
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ArrayList<BookObj> arr = new ArrayList<BookObj>();
		arr = bookDao.selectBooks();
		request.setAttribute("bookStore", arr);
		RequestDispatcher rd = request.getRequestDispatcher("BookView.jsp");
		rd.forward(request, response);
	}

}
